package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.RegistersDAO;
import com.zerosky.crm.po.Registers;
import com.zerosky.crm.service.RegistersService;
import com.zerosky.crm.util.PageInfo;

@Service(value="registersService")
public class RegistersServiceImpl implements RegistersService {
	@Autowired
	private RegistersDAO RegistersDao;

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Registers> getRegistersPageInfoList(Map map, PageInfo<Registers> page) {
			int begin = ((page.getPageNo() - 1) * page.getPageSize());
			int pageSize = page.getPageSize();

			// 写入数据
			map.put("pageNo", begin);
			map.put("pageSize", pageSize);
			List<Registers> list = RegistersDao.getRegistersList(map);
			page.setList(list);

			int count = RegistersDao.countRegisters(map);// 获取总记录
			page.setPageCount(count);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Registers> getRegistersList(Map map) {
			return RegistersDao.getRegistersList(map);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public int save(Registers Registers) {
			return RegistersDao.save(Registers);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Registers getRegistersById(Integer RegistersId) {
			return RegistersDao.getRegistersById(RegistersId);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public boolean getRegistersCorrectly(Map map) {
		Registers res = RegistersDao.getRegistersCorrectly(map);
		if (res != null) {
			return false;
		} else {
			return true;
		}

	}

}
